package com.collect.zambia.zhiAdater.zhiWords;

import android.text.TextUtils;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseItemDraggableAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.collect.zambia.R;
import com.collect.zambia.zhiBean.zhiReceive.ZHIRWordsEntity;
import com.collect.zambia.zhiHelper.ZHISysShareHelper;

public class ZHIWordsAdjuster extends BaseItemDraggableAdapter<ZHIRWordsEntity, BaseViewHolder> {

    public ZHIWordsAdjuster() {
        super(R.layout.item_words_list, null);
    }

    private ZHIWordsAdjusterClickListener mZHIWordsAdjusterClickListener;

    @Override
    protected void convert(BaseViewHolder helper, ZHIRWordsEntity item) {
        helper.setText(R.id.tv_content_des, item.getContent());

        TextView tv_content_des = helper.getView(R.id.tv_content_des);

        tv_content_des.setOnClickListener(view -> {
            if (item.isDidExt()) {
                tv_content_des.setEllipsize(TextUtils.TruncateAt.END);
                tv_content_des.setLines(2);
            } else {
                tv_content_des.setEllipsize(null);
                tv_content_des.setSingleLine(false);
            }
            item.setDidExt(!item.isDidExt());
        });

        if (mZHIWordsAdjusterClickListener != null) {
            helper.getView(R.id.iv_copy).setOnClickListener(view -> ZHISysShareHelper.copyToClipboard(mContext, item.getContent()));
            helper.getView(R.id.iv_edit).setOnClickListener(view -> mZHIWordsAdjusterClickListener.onEditClick(item));
        }
    }

    public void setZHIWordsAdjusterClickListener(ZHIWordsAdjusterClickListener zhiWordsAdjusterClickListener) {
        this.mZHIWordsAdjusterClickListener = zhiWordsAdjusterClickListener;
    }
}
